package com.jili.factory.order;

import com.jili.factory.pizza.AbsFactory;
import com.jili.factory.pizza.Pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * ClassName: OrderPizza
 * Package com.jili.factory.order
 * Description:
 *
 * @Author: 廖继礼
 * @Create: 2024/7/29
 * @Version: v1.0
 */
public class OrderPizza {

    AbsFactory absFactory;

    public OrderPizza(AbsFactory absFactory){
        setFactory(absFactory);
    }
    public void setFactory(AbsFactory absFactory){
        Pizza pizza = null;
        String orderType = "";
        do {
            orderType = getPizzaType();
            this.absFactory = absFactory;
            pizza = absFactory.createPizza(orderType);
            if (pizza != null){
                pizza.prepare();
            }else {
                System.out.println("订购失败");
                break;
            }
        }while (true);

    }


    public String getPizzaType() {
        try {
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza type: ");
            return bufferedReader.readLine();

        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }
}
